package springboot_jsp.serviceimpl;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import springboot_jsp.dao.DeptDao;
import springboot_jsp.entity.DeptEntity;
import springboot_jsp.service.DeptService;


@Service
public class DeptServiceImpl implements DeptService{
	SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
	@Autowired
	private DeptDao deptDao;
	
	@Override
	//查询所有数据
	public List<DeptEntity> findAll() {
		return deptDao.findAll();
	}

	@Override
	//查询成员信息
	public DeptEntity findByMember(String member) {
		return deptDao.findByMember(member);
	}

	@Override
	//修改部门信息
	public boolean update(DeptEntity deptEntity) {
		boolean flag=false;
		try {
			deptDao.update(deptEntity);
			System.out.println("编辑成功！");
			System.out.println("当前时间: "+df.format(new Date()));
			flag=true;
		} catch (Exception e) {
			System.out.println("编辑失败！");
			System.out.println("当前时间: "+df.format(new Date()));
		}
		return flag;
	}

	@Override
	//增加部门信息
	public boolean add(DeptEntity deptEntity) {
		boolean flag=false;
		try {
			deptDao.add(deptEntity);
			System.out.println("添加成功！");
			System.out.println("当前时间: "+df.format(new Date()));
			flag=true;
		} catch (Exception e) {
			System.out.println("添加失败！");
			System.out.println("当前时间: "+df.format(new Date()));
		}
		return flag;
	}

	@Override
	//删除部门信息
	public boolean delete(String member) {
		boolean flag=false;
		try {
			deptDao.delete(member);
			System.out.println("删除成功！");
			System.out.println("当前时间: "+df.format(new Date()));
			flag=true;
		} catch (Exception e) {
			System.out.println("删除失败！");
			System.out.println("当前时间: "+df.format(new Date()));
		}
		return flag;
	}

}
